package com.leonzhangxf.bucksdemo.order.domain.value;

import com.leonzhangxf.bucksdemo.order.domain.exception.OrderAmountIllegalException;
import com.leonzhangxf.bucksdemo.order.domain.exception.OrderWithoutAmountException;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.math.BigDecimal;

@Getter
@EqualsAndHashCode
@ToString
public class OrderAmount {

    private final BigDecimal amount;

    private final String currency;

    public OrderAmount(BigDecimal amount, String currency) {
        if (null == amount) {
            throw new OrderWithoutAmountException();
        }
        if (amount.compareTo(BigDecimal.ZERO) < 0) {
            throw new OrderAmountIllegalException("订单金额不能小于0元");
        }
        this.amount = amount;
        this.currency = currency;
    }
}
